package codeassist.popup.actions;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import codeassist.ActionContext;
import codeassist.handler.ToStringHandler;


public class ToStringAction implements IObjectActionDelegate {

	private ActionContext context = new ActionContext();
	@Override
	public void run(IAction action) {
		ToStringHandler handler = new ToStringHandler(context);
		handler.action(null);
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		this.context.setSelection(selection);//选择文件
//		Object obj = ((StructuredSelection) this.context.getSelection()).getFirstElement();
//		if ((obj instanceof IFile)) {
//			IFile file = (IFile) obj;
//			IFile configFile = file.getProject().getFile("excel_config.xml");
//			if (configFile.exists()) {
//				this.context.getMcs().println("\u5F00\u59CB\u89E3\u6790 analysis excel_config.xml");
//			} else {
//				this.context.getMcs().println(" \u914D\u7F6E\u6587\u4EF6 excel_config.xml \u6CA1\u6709\u627E\u5230 ");
//			}
//		}

	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.context.setShell(targetPart.getSite().getShell());
	}


}
